package es.ats.codington.festival.services;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;

import es.ats.codington.festival.daos.EventSignUpDAOImp;
import es.ats.codington.festival.domain.Event;
import es.ats.codington.festival.interfaces.services.IEventSignUpService;
import es.ats.codington.festival.utils.FERSDataConnection;

public class EventSignUpService implements IEventSignUpService{

	int nRows = 0;
	private Connection con;
	EventSignUpDAOImp eventSign= new EventSignUpDAOImp();
	
	public EventSignUpService() {
		
	}
	/**
	 * Methods for EventSignUpService class. Visitor registers an event
	 * @return
	 */
	public int signUpToEvent(int iDvisitor, int iDevent) {
		try{
			con = FERSDataConnection.getConnection();
			nRows = eventSign.signUpToEvent(iDvisitor, iDevent, con);
			con.close();
		}catch (SQLException e){
			System.out.println(e.getMessage());
		}
		return nRows;
	}
	/**
	 *  Methods for EventSignUpService class. Visitor unregisters an event 
	 * @return
	 */
	public int unsignUpToEvent(int iDvisitor, int iDevent){
		try{
			con = FERSDataConnection.getConnection();
			nRows = eventSign.unsignUpToEvent(iDvisitor, iDevent, con);
			con.close();
		}catch (SQLException e){
			System.out.println(e.getMessage());
		}
		return nRows;
	}
	/**
	 *  GETTER methods for EventSignUpService class 
	 * @return
	 */
	public ArrayList<Event> eventForUserService(int iDvisitor) {
		ArrayList<Event> listIdEvents = new ArrayList<Event>();
		try{
			con = FERSDataConnection.getConnection();
			listIdEvents = eventSign.eventForUser(iDvisitor, con);
			con.close();
		}catch (SQLException e){
			System.out.println(e.getMessage());
		}
		return listIdEvents;
	}
	/**
	 *  GETTER methods for EventSignUpService class 
	 * @return
	 */
	public ArrayList<Event> noEventForUserService(int iDvisitor) {
		ArrayList<Event> listIdEvents = new ArrayList<Event>();
		try{
			con = FERSDataConnection.getConnection();
			listIdEvents = eventSign.noEventForUser(iDvisitor, con);
			con.close();
		}catch (SQLException e){
			System.out.println(e.getMessage());
		}
		return listIdEvents;
	}
}